module top(

//input clk_sys,
input clk,
input rst,
input keyopen,
input [4:0] keyin,
input [3:0] keyoutup,
input [4:0] keyoutdown,

input [4:0] keyinR,
output beepR,
input keyopenR,
output [6:0] segfloorR, 
output [6:0] segupdownR,  
output [6:0] segdoorR,
output [4:0] ledinR,

output [4:0] ledin,
output [3:0] ledoutup,
output [3:0] ledoutdown,
output beep,
output [6:0] segfloor,
output [6:0] segupdown,
output [6:0] segdoor,
/* 
output wire [4:0] inreq,
output wire [4:0] outrequp,
output wire [4:0] outreqdown,
output wire [4:0] cur_floor,
output wire up,
output wire down,
output wire stop,
output wire [4:0] inreqN,
output wire [4:0] outreqUN,
output wire [4:0] outreqDN
*/
output lineL1,
output lineL2,
output lineR1,
output lineR2
);

wire clk1;
wire clk2;
divclk divclk(
	.clk(clk),
	.rst_n(rst),
	.clk_div(clk1)

); 

divclkR divclkR(
	.clk(clk),
	.rst_n(rst),
	.clk_div(clk2)


);

wire [4:0] inreq;
wire [4:0] outrequp;
wire [4:0] outreqdown;
wire [4:0] cur_floor;
wire up;
wire down;
wire stop;
wire [4:0] inreqN;
wire [4:0] outreqUN;
wire [4:0] outreqDN;

wire [4:0] inreqR;
wire [4:0] cur_floorR;
wire upR;
wire downR;
wire stopR;
wire [4:0] inreqNR;
wire [4:0] outreqUNR;
wire [4:0] outreqDNR;

get_request get_request(
	.in_reqnew(inreqN),
	.out_requpnew(outreqUN),
	.out_reqdownnew(outreqDN),
	
	.keyL(keyin),
	.out_keyup(keyoutup),
	.out_keydown(keyoutdown),
	
	.in_req(inreq),
	.out_requp(outrequp),
	.out_reqdown(outreqdown),
	
	.in_reqnewR(inreqNR),//
	.out_requpnewR(outreqUNR),//
	.out_reqdownnewR(outreqDNR),//
	.keyR(keyinR),//
	.in_reqR(inreqR),//
	
);

elevator elevator(
	.clk(clk),
	.rst(rst),
	.in_req(inreq),
	.out_requp(outrequp),
	.out_reqdown(outreqdown),
	.key_open(keyopen),
	
	.clk1(clk1),
	
	.cur_floor(cur_floor),
	.up(up),					
	.down(down),				
	.stop(stop),
	.in_reqN(inreqN),
	.out_requpN(outreqUN),
	.out_reqdownN(outreqDN)
);

elevator_r elevator_r(
	.clk(clk),
	.rst(rst),
	.in_req(inreqR),
	.out_requp(outrequp),
	.out_reqdown(outreqdown),
	.key_open(keyopenR),
	
	.clk1(clk2),
	.cur_floorL(cur_floor),
	
	.cur_floor(cur_floorR),
	.up(upR),					
	.down(downR),				
	.stop(stopR),
	.in_reqN(inreqNR),
	.out_requpN(outreqUNR),
	.out_reqdownN(outreqDNR)

);

led led(
	.in_req(inreq),
	.out_requp(outrequp),
	.out_reqdown(outreqdown),

	.ledup(ledoutup),
	.leddown(ledoutdown),
	.ledinL(ledin),
	
	.in_reqR(inreqR),
	.ledinR(ledinR)
);



seg segL(
	.cur_f(cur_floor),
	.up(up),
	.down(down),
	.stop(stop),
	.dis_cur(segfloor),
	.direc(segupdown),
	.disdoor(segdoor)
);

seg segR(
	.cur_f(cur_floorR),
	.up(upR),
	.down(downR),
	.stop(stopR),
	.dis_cur(segfloorR),
	.direc(segupdownR),
	.disdoor(segdoorR)
);


assign beep = stop;
assign beepR = stopR;

dianji left(
	.up(up),
	.down(down),
	.stop(stop),
	.line1(lineL1),
	.line2(lineL2)
);

dianji right(
	.up(upR),
	.down(downR),
	.stop(stopR),
	.line1(lineR1),
	.line2(lineR2)
);

endmodule
